package cn.com.bluemoon.daps.api.sys.factory;

import cn.com.bluemoon.daps.api.sys.RemoteSysPropertyService;
import cn.com.bluemoon.daps.api.sys.RemoteSystemDatasourceService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.system.entity.DapSystemProperty;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class RemoteSysPropertyServiceFallbackFactory implements FallbackFactory<RemoteSysPropertyService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSysPropertyServiceFallbackFactory.class);

    @Override
    public RemoteSysPropertyService create(Throwable throwable) {
        log.error("系统系统参数服务调用失败:{}", throwable.getMessage());
        return new RemoteSysPropertyService() {
            @Override
            public ResultBean<Map<String, List<DapSystemProperty>>> getPropertyInfo(List<String> groupList) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiSystem.PROD_SERVICE, "获取系统参数信息失败");
            }
        };
    }
}
